package com.aaa.backsystem.controller;

import com.aaa.backsystem.entity.LayuiTable;
import com.aaa.backsystem.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

/**
 * fileName:DangerController
 * description:
 * author:gyc
 * createTime:2020/8/22 16:20
 * version:1.0.0
 */
@Controller
@RequestMapping("/danger")
public class DangerController extends BaseController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/toDanger")
    public String toDanger(){
        return "danger/danger";
    }

    /**
     * 查询隐患列表
     * @return
     */
    @GetMapping("/findDanger")
    @ResponseBody
    public LayuiTable findDanger(Integer page, Integer limit){
        /**
         * 调用微信端接口方法
         * String.class：返回值类型
         */
        LayuiTable layuiTable = restTemplate.getForObject("http://localhost:9091/wxDanger/findDanger/{page}/{limit}", LayuiTable.class,page,limit);
        return layuiTable;
    }

    /**
     * 处理隐患
     * @return
     */
    @GetMapping("/handleDanger")
    @ResponseBody
    public Result handleDanger(Integer dangerId){
        /**
         * 调用微信端接口方法
         */
        try {
            restTemplate.getForObject("http://localhost:9091/wxDanger/handleDanger/{dangerId}",Result.class,dangerId);
            return success();
        } catch (RestClientException e) {
            e.printStackTrace();
        }
        return error();
    }

}
